package org.example.classloader.ASM;

import jdk.internal.org.objectweb.asm.AnnotationVisitor;
import jdk.internal.org.objectweb.asm.MethodVisitor;
import jdk.internal.org.objectweb.asm.Opcodes;

public class FilterMethodVisitor extends MethodVisitor {

    private final FilterClassVisitor classVisitor;
    String methName;

    public FilterMethodVisitor(String name, MethodVisitor methodVisitor, FilterClassVisitor transactionClassVisitor) {

        super(Opcodes.ASM5, methodVisitor);
        this.methName = name;
        this.classVisitor = transactionClassVisitor;
    }

    @Override
    public AnnotationVisitor visitAnnotation(String s, boolean b) {

        if (s.contains("Transaction")) {
            this.classVisitor.addTranMehod(this.methName);
        }
        return super.visitAnnotation(s, b);
    }
}
